// src/api.js
import axios from 'axios';

const apiClient = axios.create({
  baseURL: 'http://8.138.12.59:1999', // 后端服务器',
  withCredentials: false,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json'
  }
});

export default {
      // 登录
      Login(phone_num,password,user_type) {
      return apiClient.get("/user/login", {
          params: { phone_num, password, user_type },
        })
      },
    // 注册
    Register(data) {
      return apiClient.post('/user/register', data,{
        timeout: 2000 // 设置超时时间为 10 秒 (10000 毫秒)
      })
    },
    //展示教师团队
    getTechTeam(id){
      return apiClient.get('/teacher/showteam', {
        params: {
          course_id:id
        }
      })
    },
    // 展示首页评论
  showGoodSemester(course_id) {
    return apiClient.get(`/comment/excellent?course_id=${course_id}`);
  },
  // 获取作业列表
  getAssignments(user_id) {
    return apiClient.get(`/assignments?user_id=${user_id}`);
  },
  // 获取作业详情
  getAssignmentDetails(id, user_id) {
    return apiClient.get(`/assignments/${id}/${user_id}`);
  },
  // 提交作业
  submitAssignment(data) {
    return apiClient.post('/assignments/submit', data, {
      headers: {
          'Content-Type': 'multipart/form-data'
      }}
    );
  },
  // 发送互评
  submitPeerReview(data) {
    return apiClient.post('/peer-review/submit', data);
  },
  // 获取单元测试列表
  getUnitTests(unit_id) {
    return apiClient.get(`/unit/getUnitTests?unit_id=${unit_id}`);
  },
  // 获取单元测试问题详情
  getTestQuestions(test_id) {
    return apiClient.get(`/unit/getTestQuestions?test_id=${test_id}`);
  },
  // 提交单元测试答案
  submitTestAnswers(data) {
    return apiClient.post('/unit/submitTestAnswers', data);
  },
  //单元下的作业、测试粗列表
  getUnitHmkTestBySem(semester_id,user_id){
    return apiClient.get("/assignments",
      {
        params:{
          user_id:user_id,
          semester_id:semester_id,
        }
      }
    ) ;
  },
  getHmkStage(user_id,hmk_id){
    return apiClient.get("/assignments/hmkstage",{
      params:{
        user_id:user_id,
        hmk_id:hmk_id
      }
    })
  },
  getTestStage(user_id,hmk_id){
    return apiClient.get("/assignments/teststage",{
      params:{
        user_id:user_id,
        test_id:hmk_id
      }
    })
  }
};
